package com.ruoyi.process.pipemaintainence2.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.process.pipemaintainence2.domain.TBpmnApproval;
import com.ruoyi.process.pipemaintainence2.service.ITBpmnApprovalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审批意见Controller
 *
 * @author Xianlu Tech
 * @date 2019-12-05
 */
@Controller
@RequestMapping("/process/approval")
public class TBpmnApprovalController extends BaseController {
    private String prefix = "process/pipeMaintainence2/approval";

    @Autowired
    private ITBpmnApprovalService tBpmnApprovalService;

    @RequiresPermissions("process:approval:view")
    @GetMapping()
    public String approval() {
        return prefix + "/approval";
    }

    /**
     * 查询审批意见列表
     */
    @RequiresPermissions("process:approval:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBpmnApproval tBpmnApproval) {
        startPage();
        List<TBpmnApproval> list = tBpmnApprovalService.selectTBpmnApprovalList(tBpmnApproval);
        return getDataTable(list);
    }

    /**
     * 导出审批意见列表
     */
    @RequiresPermissions("process:approval:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBpmnApproval tBpmnApproval) {
        List<TBpmnApproval> list = tBpmnApprovalService.selectTBpmnApprovalList(tBpmnApproval);
        ExcelUtil<TBpmnApproval> util = new ExcelUtil<TBpmnApproval>(TBpmnApproval.class);
        return util.exportExcel(list, "approval");
    }

    /**
     * 新增审批意见
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存审批意见
     */
    @RequiresPermissions("process:approval:add")
    @Log(title = "审批意见", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBpmnApproval tBpmnApproval) {
        return toAjax(tBpmnApprovalService.insertTBpmnApproval(tBpmnApproval));
    }

    /**
     * 修改审批意见
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        TBpmnApproval tBpmnApproval = tBpmnApprovalService.selectTBpmnApprovalById(id);
        mmap.put("tBpmnApproval", tBpmnApproval);
        return prefix + "/edit";
    }

    /**
     * 修改保存审批意见
     */
    @RequiresPermissions("process:approval:edit")
    @Log(title = "审批意见", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBpmnApproval tBpmnApproval) {
        return toAjax(tBpmnApprovalService.updateTBpmnApproval(tBpmnApproval));
    }

    /**
     * 删除审批意见
     */
    @RequiresPermissions("process:approval:remove")
    @Log(title = "审批意见", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tBpmnApprovalService.deleteTBpmnApprovalByIds(ids));
    }
}
